Understanding the Two Main APIs in RTK Query: createApi and fetchBaseQuery
RTK Query uses two main APIs — createApi and fetchBaseQuery — that work together to simplify data fetching, caching, and synchronization in Redux Toolkit.
createApi is the core function used to define an API service in RTK Query.
It specifies the reducer path, base query, and a set of endpoints (queries and mutations).
It automatically generates hooks like useGetPostsQuery or useAddPostMutation for React components.
fetchBaseQuery is a small wrapper around the native fetch API.
It serves as the default base query function used inside createApi.
It handles common tasks such as setting base URLs, headers, and parsing JSON responses.
In summary, fetchBaseQuery performs the network requests, while createApi defines how those requests integrate with Redux state and React components.